package com.sanyang.pda.ui.scancodequery;

import android.os.Bundle;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.sanyang.pda.bean.ScanBean;
import com.sanyang.pda.bean.SearchStockDetailBean;
import com.sanyang.pda.contract.StockSearchContract;
import com.sanyang.pda.presenter.StockSearchPresenter;
import com.sanyang.pda.utils.StringConfig;
import com.sanyang.pda.utils.Utils;
import com.sanyang.pda.view.ScanButView;
import com.wangshen.base.app.AppActivityKey;
import com.wangshen.base.ui.mvp.base.ui.BaseMvpActivity;
import com.wangshen.projectbase.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

@Route(path = AppActivityKey.STOCKDETAILACTIVITY)
public class StockDetailActivity extends BaseMvpActivity<StockSearchPresenter> implements StockSearchContract.View {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.title)
    FrameLayout title;
    @BindView(R.id.tv_storagebinid)
    TextView tvStoragebinid;
    @BindView(R.id.tv_sequenceno)
    TextView tvSequenceno;
    @BindView(R.id.tv_pallet)
    TextView tvPallet;
    @BindView(R.id.tv_articleId)
    TextView tvArticleId;
    @BindView(R.id.tv_articleName)
    TextView tvArticleName;
    @BindView(R.id.tv_spec)
    TextView tvSpec;
    @BindView(R.id.tv_batchNo)
    TextView tvBatchNo;
    @BindView(R.id.tv_price)
    TextView tvPrice;
    @BindView(R.id.tv_amount)
    TextView tvAmount;
    @BindView(R.id.tv_stockNum)
    TextView tvStockNum;
    @BindView(R.id.tv_entryTime)
    TextView tvEntryTime;
    @BindView(R.id.tv_stockStatus)
    TextView tvStockStatus;
    @BindView(R.id.tv_checkStatus)
    TextView tvCheckStatus;
    @BindView(R.id.tv_productTime)
    TextView tvProductTime;
    @BindView(R.id.tv_expiringTime)
    TextView tvExpiringTime;
    @BindView(R.id.scan)
    ScanButView scan;
    @BindView(R.id.tv_lastCountTime)
    TextView tvLastCountTime;

    @Override
    public int getView() {
        return R.layout.activity_stockdetail;
    }

    @Override
    public void initView() {
        scan.setScanCallBack(new ScanButView.ScanCallBack() {
            @Override
            public void callBack(ScanBean scanBean) {
                if (scanBean.getType() == 2 || scanBean.getType() == 1) {
                    presenter.inventoryQuery(scanBean.getCode());
                }
            }
        });
    }

    @Override
    public void initLinsenterner() {

    }

    @Override
    public void getData() {
        SearchStockDetailBean searchStockDetailBean = (SearchStockDetailBean) getIntent().getExtras().getSerializable(StringConfig.BEAN);
        if (searchStockDetailBean != null)
            setData(searchStockDetailBean);
    }


    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void setData(SearchStockDetailBean searchStockDetailBean) {
        tvAmount.setText(searchStockDetailBean.getStockNum() + "");
        tvArticleId.setText(searchStockDetailBean.getArticleId());
        tvArticleName.setText(searchStockDetailBean.getArticleName());
        tvBatchNo.setText(searchStockDetailBean.getBatchNo());
        if (searchStockDetailBean.getCheckStatus() == 0){
            tvCheckStatus.setText(getString(R.string.without_quality_inspection));
        }else if (searchStockDetailBean.getCheckStatus() == 10){
            tvCheckStatus.setText(getString(R.string.quality_inspection));
        }else {
            tvCheckStatus.setText(getString(R.string.have_quality_inspection));
        }
        tvSpec.setText(searchStockDetailBean.getSpec());
        tvEntryTime.setText(searchStockDetailBean.getEntryTime());
        tvExpiringTime.setText(searchStockDetailBean.getExpiringTime());
        tvPallet.setText(searchStockDetailBean.getPallet());
        //tvPrice.setText(searchStockDetailBean.getPrice() + "");
        tvSequenceno.setText(searchStockDetailBean.getSequenceNo());
        tvProductTime.setText(searchStockDetailBean.getProductTime());
        //tvSpec.setText(searchStockDetailBean.getSpec());
        tvStoragebinid.setText(searchStockDetailBean.getStoragebinId());
        tvStockNum.setText(searchStockDetailBean.getStockNum());
        tvStockStatus.setText(Utils.getStockState(mContext,searchStockDetailBean.getStockStatus()));
        tvLastCountTime.setText(searchStockDetailBean.getLastCountTime());
    }

    @Override
    public StockSearchPresenter getPresenter() {
        return new StockSearchPresenter();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
